#include <iostream>

#include <memory>
#include <vector>
using std::cout;
using std::endl;

const int kItemSize = 5;

class Item
{
public:
    Item(int id):id_(id)
    {
        cout << "Constructor, Item id = "<< id_ << endl;
    }
    ~Item()
    {
        cout << "Destructor, Item id = "<< id_ << endl;
    }
    int getId()
    {
        return id_;
    }
private:
    int id_;
};



void testNormalPointer(void)
{
    cout << "testNormalPointer entry" << endl;
    std::vector<Item *> itemVector;

    cout << "push item:" << endl;
    for(int i = 0; i < kItemSize; i++)
    {
        Item *pItem = new Item(i);
        itemVector.push_back(pItem);
    }

    cout << "traverse item:" << endl;
    for(int i = 0; i < itemVector.size(); i++)
    {
        cout << "Item id = " << itemVector.at(i)->getId() << endl;
    }

    cout << "testNormalPointer leave" << endl;
}

void testSmartlPointer(void)
{
    cout << "testSmartlPointer entry" << endl;
    std::vector<std::shared_ptr<Item>> itemVector;

    cout << "push item:" << endl;
    for(int i = 0; i < kItemSize; i++)
    {
        std::shared_ptr<Item> pItem = std::make_shared<Item>(i);
        itemVector.push_back(pItem);
        pItem.use_count()
    }

    cout << "traverse item:" << endl;
    for(int i = 0; i < itemVector.size(); i++)
    {
        cout << "Item id = " << itemVector.at(i)->getId() << endl;
    }

    cout << "testSmartlPointer leave" << endl;
}

int main()
{
    cout << "------------- Pointer test entry -------------" << endl;
    testNormalPointer();
    cout << "\n\n----------------------------------------------\n\n" << endl;
    testSmartlPointer();
    cout << "\n\n------------- Pointer test leave -------------" << endl;
    return 0;
}
